// fetchSummaryData

export default function ({ summaryData, summaryPlanData, isAfter }) {
  const icaoCodes = Object.keys(summaryPlanData.airport);

  let totRealDep = 0;
  let totRealArr = 0;

  let totPlanDep = 0;
  let totPlanArr = 0;

  const tableSummaryData = icaoCodes.map((icao) => {
    totRealDep += summaryData.airport[icao].type.DEP;
    totRealArr += summaryData.airport[icao].type.ARR;

    totPlanDep += summaryPlanData.airport[icao].type.DEP;
    totPlanArr += summaryPlanData.airport[icao].type.ARR;

    return {
      name: icao,
      depPlanValue: summaryPlanData.airport[icao].type.DEP,
      depRealValue: isAfter ? summaryData.airport[icao].type.DEP : "待统计",
      arrPlanValue: summaryPlanData.airport[icao].type.ARR,
      arrRealValue: isAfter ? summaryData.airport[icao].type.ARR : "待统计",
      totPlanValue: summaryPlanData.airport[icao].total,
      totRealValue: isAfter ? summaryData.airport[icao].total : "待统计",
    };
  });

  tableSummaryData.push({
    name: "终端区",
    depPlanValue: totPlanDep,
    depRealValue: isAfter ? totRealDep : "待统计",
    arrPlanValue: totPlanArr,
    arrRealValue: isAfter ? totRealArr : "待统计",
    totPlanValue: totPlanDep + totPlanArr,
    totRealValue: isAfter ? totRealDep + totRealArr : "待统计",
  });

  return tableSummaryData;
}
